package com.soujiayi.view;

import android.app.Activity;
import android.app.AlertDialog;
import android.content.Context;
import android.os.Bundle;
import android.view.Display;
import android.view.View;
import android.view.WindowManager;
import android.widget.Button;
import android.widget.TextView;

import com.soujiayi.activity.R;

public class NormalDialog extends AlertDialog {

	private Activity context;
	private String contentStr;
	public Button comfirm;
	private boolean isCreateOnclick = true;

	public NormalDialog(Context context, int theme, String contentStr) {
		super(context, theme);
		this.context = (Activity) context;
		this.contentStr = contentStr;
	}
	
	public NormalDialog(Context context, int theme, String contentStr, boolean isCreateOnclick) {
		super(context, theme);
		this.context = (Activity) context;
		this.contentStr = contentStr;
		this.isCreateOnclick = isCreateOnclick;
	}

	public NormalDialog(Context context) {
		super(context);
	}

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.normal_dialog);
		TextView content = (TextView) this.findViewById(R.id.normal_dialog_content);
		content.setText(this.contentStr);
		comfirm = (Button) this.findViewById(R.id.normal_dialog_confirm);
		if(isCreateOnclick){
			comfirm.setOnClickListener(new android.view.View.OnClickListener() {
				@Override
				public void onClick(View v) {
					NormalDialog.this.cancel();
				}
			});
		}

		WindowManager windowManager = context.getWindowManager();
		Display display = windowManager.getDefaultDisplay();
		WindowManager.LayoutParams lp = this.getWindow().getAttributes();
		lp.width = (int) (display.getWidth() * 0.8);
		lp.height = (int) (display.getHeight() * 0.25);
		//lp.alpha = 0.8f;
		this.getWindow().setAttributes(lp);

	}

}